package com.wwl.cms.utils.designModeTest.mediator.smarthouse;

import java.util.HashMap;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/9/26 17:13
 * @description:
 */
public class ConcreteMediator extends Mediator {
    //集合，放入所有的同事对象
    private HashMap<String,Colleague> colleagueHashMap;
    private HashMap<String,String> interMap;

    public ConcreteMediator(){
        colleagueHashMap = new HashMap<String, Colleague>();
        interMap = new HashMap<String, String>();
    }

    public void Register(String colleagueName,Colleague colleague){
        colleagueHashMap.put(colleagueName,colleague);
        if (colleague instanceof Alarm){
            interMap.put("Alam",colleagueName);
        }else if(colleague instanceof CoffeeMachine){
            interMap.put("CoffeeMachine",colleagueName);
        }else if (colleague instanceof TV){
            interMap.put("TV",colleagueName);
        }else if (colleague instanceof Colleague){
            interMap.put("Curtains",colleagueName);
        }
    }
    //具体中介的核心方法
    //根据得到消息，完成对应任务

    @Override
    public void GetMessage(int stateChange,String colleagueName){

        //处理闹钟发出的消息
        if(colleagueHashMap.get(colleagueName) instanceof Alarm){
            if (stateChange==0){
                ((CoffeeMachine)(colleagueHashMap.get(interMap.get("CoffeeMachine")))).StartCoffee();
                ((TV)(colleagueHashMap.get(interMap.get("TV")))).StopTv();
            }
        }else if (colleagueHashMap.get(colleagueName) instanceof CoffeeMachine){
            ((Curtains)(colleagueHashMap.get(interMap.get("Curtains")))).UpCurtains();
        }else if (colleagueHashMap.get(colleagueName) instanceof TV){

        }else if (colleagueHashMap.get(colleagueName) instanceof Curtains){

        }
    }
    @Override
    public  void SendMessage(){

    }
}
